﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeCamp12.Domain;
using System.IO;
using log4net;

namespace CodeCamp12.BLL
{
    public class SponsorsBL
    {
        private ILog log = LogManager.GetLogger("CodeCamp12.BLL");

        /// <summary>
        /// Returns all sponsor types
        /// </summary>
        /// <returns>SponsorType</returns>
        public List<SponsorType> GetAllSponsorTypes()
        {
            var sponsorDataManagement = new SponsorDataManagement();
            
            try
            {
                return sponsorDataManagement.GetAllSponsorTypes();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }

        /// <summary>
        /// Returns all sponsors from the website
        /// </summary>
        /// <returns>Sponsor</returns>
        public List<Sponsor> GetAllSponsors() 
        {
            var sponsorDataManagement = new SponsorDataManagement();
            try
            {
                return sponsorDataManagement.GetAllSponsors();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }

        /// <summary>
        /// Inserts new sponsor for the website
        /// </summary>
        /// <param name="sponsor"></param>
        public void InsertSponsor(Sponsor sponsor)
        {
            var sponsorDataManagement = new SponsorDataManagement();
            try
            {
                sponsorDataManagement.InsertSponsor(sponsor);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Updates sponsor for the website
       /// </summary>
       /// <param name="sponsor"></param>
        public void UpdateSponsor(Sponsor sponsor)
        {
            
            var sponsorDataManagement = new SponsorDataManagement();
            try
            {
               sponsorDataManagement.UpdateSponsor(sponsor);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Deletes sponsor from the website
        /// </summary>
        /// <param name="sponsor"></param>
        public void DeleteSponsor(Sponsor sponsor)
        {
            var sponsorDataManagement = new SponsorDataManagement();
            try
            {
                sponsorDataManagement.DeleteSponsor(sponsor);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }
        
        /// <summary>
        /// Gets the sponsor with ID passed in parametars
        /// </summary>
        /// <param name="sponsorId"></param>
        /// <returns></returns>
        public Sponsor GetSponsorById(string sponsorId)
        {
            var sponsorDataManagement = new SponsorDataManagement();
            try
            {
                return sponsorDataManagement.GetSponsorById(new Guid(sponsorId));
            }
            catch(Exception ex)
            {
                log.Error(ex); 
                throw;
            }
            
        }
    }
}
